package com.project_test.kun.travelling_1st.HomePage.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


import com.project_test.kun.travelling_1st.Discovery.Discover_Detail_Activity;
import com.project_test.kun.travelling_1st.HomePage.Util.URL;
import com.project_test.kun.travelling_1st.HomePage.adapter.HomePDetilAdapter;
import com.project_test.kun.travelling_1st.HomePage.category.HomePListItemIndex;
import com.project_test.kun.travelling_1st.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HomePageDetilActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

    private HomePListItemIndex mIndex;
    private List<Map<String,Object>> data;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_page__detil);
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            mIndex = (HomePListItemIndex) extras.getSerializable("index");
            initView();
        }else{
            Toast.makeText(HomePageDetilActivity.this, "数据传输错误", Toast.LENGTH_SHORT).show();
        }
    }

    private void initView() {
        TextView toolText= (TextView) findViewById(R.id.toolText);
        ListView imageList= (ListView) findViewById(R.id.homePDetil_listView);
        toolText.setText(mIndex.getSub_title());
        initData();
        HomePDetilAdapter adapter=new HomePDetilAdapter(this,data);
        imageList.setAdapter(adapter);
        //对item进行点击监听
        imageList.setOnItemClickListener(this);
    }

    private void initData() {
        data=new ArrayList<>();
        Map<String,Object> mapBig=new HashMap<>();
        mapBig.put("pic",mIndex.getPic_big());
        mapBig.put("id",mIndex.getPic_big_id());
        data.add(mapBig);
        Map<String,Object> mapS1=new HashMap<>();
        mapS1.put("pic",mIndex.getPic_s1());
        mapS1.put("id",mIndex.getPic_s1_id());
        data.add(mapS1);
        Map<String,Object> mapS2=new HashMap<>();
        mapS2.put("pic",mIndex.getPic_s2());
        mapS2.put("id",mIndex.getPic_s2_id());
        data.add(mapS2);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Intent intent=new Intent(HomePageDetilActivity.this,Discover_Detail_Activity.class);
        String detailPath= URL.DETAIL_PATH_1+(int)(data.get(i).get("id"))+URL.DETAIL_PATH_2;
        intent.putExtra("detailPath",detailPath);
        startActivity(intent);
    }
}
